// var type=document.getElementById("typeId");
// var Id = type.value;
// console.log(typeId);


function page(date1,date2,typeId) {
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table','laydate'], function () {
        var table = layui.table
            , admin = layui.admin;
        table.render({
            elem: '#test-table-operate'
            , url: 'http://localhost:8080/bill/list-page?typeId='+typeId
            , width: admin.screen() > 1 ? 892 : ''
            , height: 332
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'id', width: 80, title: 'ID', sort: true, fixed: 'left'}
                , {field: 'title', width: 80, title: '标题'}
                , {field: 'billTime', width: 80, title: '时间'}
                , {field: 'price', width: 80, title: '金额'}
                , {field: 'typeId', width: 80, title: '类别'}
                , {field: 'explain', width: 200, title: '说明'}
                , {width: 178, align: 'center', fixed: 'right',title: '操作', toolbar: '#test-table-operate-barDemo'}
            ]],
            parseData:function(res){
                console.log(res)
                var data = res.data;
                for(index in data){
                    var birthday= data[index].billTime;
                    var time = new Date(birthday);
                    data[index].billTime= time.getFullYear() + "-" + (time.getMonth() + 1) + "-" + time.getDate();
                }
            }
            , page: true
        });

        //监听表格复选框选择
        table.on('checkbox(test-table-operate)', function (obj) {
            console.log(obj)
        });
        //监听工具条
        table.on('tool(test-table-operate)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                layer.confirm('确定删除此条账单吗', function (index) {
                    console.log(data.id);
                    var id=data.id;
                    $.ajax({
                        url:"http://localhost:8080/bill/delete?id="+id,
                        async: false,
                        type:"GET",
                        dataType: "json",
                        // jsonp:"callback",
                        // jsonpCallback:"success_jsonp",
                        success: function(data){

                        }
                    })
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                // layer.alert('编辑行：<br>' + JSON.stringify(data));
                var storage = window.localStorage;
                console.log(storage)
                var setData = JSON.stringify(data);
                storage.setItem('update',setData);
                location.href='/bill_web/views/home/update.html';
            }
            console.log(1111);

        });

        var $ = layui.$, active = {
            getCheckData: function () { //获取选中数据
                var checkStatus = table.checkStatus('test-table-operate')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            },
            isAll: function () { //验证是否全选
                var checkStatus = table.checkStatus('test-table-operate');
                layer.msg(checkStatus.isAll ? '全选' : '未全选')
            }
        };

        $('.test-table-operate-btn .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        var laydate = layui.laydate;

        //示例代码
        //常规用法
        laydate.render({
            elem: '#test-laydate-normal-cn1'
        });
        laydate.render({
            elem: '#test-laydate-normal-cn2'
        });

    });
}

